[英]onclick=“location.href='link.html'” does not load page in Safari
I cannot get onclick="location.href='link.html'"
to load a new page in Safari (5.0.4). 我无法使用
onclick="location.href='link.html'"
在Safari(5.0.4)中加载新页面。
I am building a drop-down navigation menu using the <select>
and <option>
HTML tags. 我正在使用
<select>
和<option>
HTML标记构建一个下拉导航菜单。 I am using the onclick
handler to load a new page after a menu-item is clicked, but nothing happens in Safari. 我在点击菜单项后使用
onclick
处理程序加载新页面,但Safari中没有任何反应。 (I have successfully tested in FF & Opera.) I know that there are many onclick
bugs in Safari, but I haven't found any solutions that address this specific issue. (我已经在FF和Opera中成功测试过了。)我知道Safari中存在许多
onclick
错误,但我没有找到解决此特定问题的任何解决方案。
You can see a sample of my code below: 您可以在下面看到我的代码示例:
<select>
<option onclick="location.href='unit_01.htm'">Unit 1</option>
</select>
and 和
<select>
<option onclick="location.href='#5.2'">Bookmark 2</option>
</select>
I do not (and prefer not) to have any javascript embedded in the head section of my HTML. 我不(并且不愿意)在我的HTML的head部分中嵌入任何javascript。 I am developing the page for someone who does not know how to use javascript--so the simpler the code, the better.)
我正在为不知道如何使用javascript的人开发页面 - 所以代码越简单越好。)
What JavaScript code would make the menu-item clickable in all-browsers? 什么JavaScript代码可以使菜单项在所有浏览器中都可点击? (Please verify compatibility with IE.)
(请验证与IE的兼容性。)
Try this: 试试这个:
onclick="javascript:location.href='http://www.uol.com.br/'"
Worked fine for me in Firefox, Chrome and IE (wow!!) 在Firefox,Chrome和IE中为我工作得很好(哇!!)
Use jQuery....I know you say you're trying to teach someone javascript, but teach him a cleaner technique... for instance, I could: 使用jQuery ....我知道你说你正在尝试教某人javascript,但教他一种更清洁的技术...例如,我可以:
<select id="navigation">
<option value="unit_01.htm">Unit 1</option>
<option value="#5.2">Bookmark 2</option>
</select>
And with a little jQuery, you could do: 使用一点jQuery,你可以做到:
$("#navigation").change(function()
{
document.location.href = $(this).val();
});
Unobtrusive, and with clean separation of logic and UI. 不引人注目,并且清晰地分离逻辑和UI。
放手一搏:
<option onclick="parent.location='#5.2'">Bookmark 2</option>
You can try this: 你可以试试这个:
<a href="link.html">
<input type="button" value="Visit Page" />
</a>
This will create button inside a link and it works on any browser 这将在链接中创建按钮,它可以在任何浏览器上运行
I had the same error. 我有同样的错误。 Make sure you don't have any
<input>
, <select>
, etc. name="location"
. 确保您没有任何
<input>
, <select>
等name="location"
。
try 尝试
<select onchange="location=this.value"> <option value="unit_01.htm">Unit 1</option> <option value="#5.2" selected >Bookmark 2</option> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.