0

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>
9
  • sorry... what do you mean.... Commented Jul 15, 2015 at 3:44
  • Can you show what does not work and what you mean by a data tag with quites? Commented Jul 15, 2015 at 3:46
  • I cannot put the tag ('code') inside the href data tag. As I cannot use both ' and " inside the tag. Commented Jul 15, 2015 at 3:46
  • Show what you mean....what is the "invalid" code Commented Jul 15, 2015 at 3:50
  • The code becomes invalid and does not work when I put the link inside the data-content=" " tag I just put in the question on the bottom. If I put " around all of it, the href and chat it doesn't read the script. It just opens the chat page as it would by a default link. Commented Jul 15, 2015 at 3:52

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Using this links me to website/"chat"
0

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>

3 Comments

Thanks for taking the time. With this, it loads the page /chat but still as a normal link, it breaks the script. Should I try to make a JavaScript or find one to getElementById instead? I've tried a bunch of things now - but it's still not popping up, just a regular link.
Try adding "_blank" in window.open. window.open(url,'name','toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no,height=600,width=330', '_blank');
Still opens in the same window. So I guess it's the JavaScript not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.