0
votes

I want to pass one html page to a jquery function. My html page is like this


var string="
    <html>
     <body>
        <p class='myclass' >some content comees hre</p>
        <p><img src='localhost/images/img1.jpg' border='0' width='100' height='100' ></p>
     </body>
    </html>";

I tried pass this string to a function like this

var varfunc_call= <a href="#" onclick="JQuery.myplugin.Myfunction('"+string+"')">Click&lt/a>

I cannot change single quotes in my string. In function call area with out single quotes its calling function. But inside function definition string showing some errors. Also all single quotes are automatically changing to double quotes.

How can I fix this issude. Please help me.

1
It's not valid JavaScript to include carriage returns inside your string like that - is that really what your source looks like for var string = "..."; or have you just done that to try to make it look prettier specifically for your question? Your var varfunc_call= <a ... is also invalid syntax. Can you please be a bit clearer about what you're trying to do? What is the "function" you refer to? - nnnnnn
To use multi-line strings in javascript, you must end each line with a backslash without any trailing whitespace. As nnnnnn said, what you've got there isn't valid. - flesk
P.S. to format code on StackOverflow you don't have to manually type the &lt; and <pre> and so forth. For blocks, type normally then select the text and click the {} button (or indent each line 4 spaces). For little snippets like in this comment just "quote" the code using the ` character. (I'd edit your question to fix it, but I can't tell if your intention is for the string to include html entities like &lt; or the actual < less-than character.) - nnnnnn
agreed with nnnnn - couldn't quite figure out what are you trying to do - alonisser

1 Answers

2
votes

If you're looking to generate a link that excecutes some function with a heavy and complex string, you shouldn't be concatenating it to HTML.

You can use:

<script type="text/javascript>
    function argumentedFunction ()
    {
        var string = "<html><body><p class='myclass'>some content comees hre</p><p><img src='localhost/images/img1.jpg' border='0' width='100' height='100' ></p></body></html>";
        return jQuery.myplugin.Myfunction(string);
    }

    var varfunc_call= '<a href="#" onclick="argumentedFunction()">Click</a>';
</script>