简体   繁体   中英

Open DIV button in New Window

I have seen this answered several ways here in Stack Overflow, but after attempting the solutions nothing is working for my button. Here is the code I am using:

<center>
<div onclick="parent.location='http://google.com'" data-mce-onclick=""><button class="button"><font size=”6”>Visit Google</font></button></div>
</center>

The use of parent.location causes google to load in the current window. I have attempted open.window open.window.href adding ,'_blank' and several other adjustments, but for whatever reason it still loads in the same window, or I lose the ability to link at all. What is the simplest way to adjust this code?

parent.location references the same window. And I don't know where you got the ideas for the other things you tried, but window.open seems to be what you're looking for:

<div onclick="window.open('http://google.com')" data-mce-onclick="">
  <button class="button"><font size=”6”>Visit Google</font></button>
</div>

It's worth noting also that you're using very old and deprecated tags. center and font should be replaced with CSS styling.

您可以使用http://www.w3schools.com/jsref/met_win_open.asp中记录的window.open

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM