Codey93
Codey93

Reputation: 129

JavaScript window.open onclick ('url')

I just figured out that I needed this link to be inside a data tag, because the data uses " ", and I can't include both.

Is this possible to do with document.getElementById("id")?

Or do I need another script for this? As you can tell I'm not the best with JavaScripts yet. Hope to learn a thing or two.

<a href="chat" onclick="return popitup('chat')">Pop</a>

<script>
function popitup(url) {
newwindow=window.open(url,'name','toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no,height=600,width=330');
if (window.focus) {newwindow.focus()}
return false;
}
</script>


<a href="#" class="emotes show-pop btn btn-default top" data-title="Settings" data-content="<a href="chat" onclick="return popitup('chat')">Pop</a>"><img src="img/settings.png"></a>

Upvotes: 0

Views: 306

Answers (2)

Adersh M
Adersh M

Reputation: 586

After referring this stackoverflow post, I tried to reproduce your code as below. Thing you missed is that you need to escape '<','>' and '"'

<a href="chat" onclick="return popitup('chat')">Pop</a>

<script>
function popitup(url) {
newwindow=window.open(url,'name','toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no,height=600,width=330');
if (window.focus) {newwindow.focus()}
return false;
}
</script>

<a href="#" class="emotes show-pop btn btn-default top" data-title="Settings" data-content='&lt;a href=&quot;chat&quot; onclick=&quot;return popitup("chat")&quot;&gt;Pop&lt;/a&gt;'>
    <img src="img/settings.png">
 </a>

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

You need to escape the " in the attribute value

<a href="#" class="emotes show-pop btn btn-default top" data-title="Settings" data-content="<a href=&quot;chat&quot; onclick=&quot;return popitup('chat')&quot;>Pop</a>"><img src="img/settings.png"></a>

Upvotes: 1

Related Questions