JavaScript window.location在内容编辑器webpart中不起作用

时间:2012-08-23 07:41:18

标签: javascript html dom sharepoint-2010 content-editor

我的问题是,以下脚本及其window.location函数在sharepoint内容编辑器webpart中不起作用。我已经将它作为一个独立的测试,它工作正常,但是一旦我将它插入到内容编辑器webpart中,脚本执行时似乎没有任何事情发生。

我很感激任何帮助

<script type="text/javascript">
    function redirect(){
       var search = document.getElementById('searchtxt').value;
       var url = "test.com/test.aspx?s="+search;
       window.location = "http://"+url+"";
       return;
    }
    </script>
    <input type="text" id="searchtxt"/> <input type="submit" value="Search" onclick="return redirect()"/>

3 个答案:

答案 0 :(得分:0)

尝试使用window.location.hrefwindow.location.replace()

答案 1 :(得分:0)

如果编辑器位于iframe中,则需要定位top窗口:

window.top.location = "http://"+url+"";

您还应该确保编辑器接受脚本标记(并非所有编辑都这样做)。

答案 2 :(得分:0)

您可以使用此document.location.href='http://someurl.com/'

相关问题