Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将完整html页面源代码保存在Javascript变量中_Javascript_Jquery_Html_Ajax - Fatal编程技术网

将完整html页面源代码保存在Javascript变量中

将完整html页面源代码保存在Javascript变量中,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我搜索将html页面中的源代码保存在Javascript变量中的最佳方法。 html源代码是用php和mysql加载的,例如如下所示: <!DOCTYPE html> <html> <body> <h2>HTML Images</h2> <p>HTML images are defined with the img tag:</p> <img src="w3schools.jpg" alt="W3" w

我搜索将html页面中的源代码保存在Javascript变量中的最佳方法。 html源代码是用php和mysql加载的,例如如下所示:

<!DOCTYPE html>
<html>
<body>

<h2>HTML Images</h2>
<p>HTML images are defined with the img tag:</p>

<img src="w3schools.jpg" alt="W3" width="104" height="142">

</body>
</html>

HTML图像
HTML图像使用img标记定义:

如果我尝试简单地将其保存到变量

var html        = "<?php echo $my_html; ?>";
var html=”“;

我有不同的错误。例如
uncaughtsyntaxerror:Unexpected-token'您不需要单独设置JavaScript变量<代码>document.documentElement.outerHTML是对HTML内容的引用

var markup=document.documentElement.outerHTML;
console.log(标记)

HTML图像
HTML图像使用img标记定义:


由于您使用的是PHP,我建议在设置JS变量之前使用本机函数。 你试过了吗



您是否尝试转义字符串?不工作,然后我返回“未捕获的SyntaxError:无效或意外令牌”。您好,这是什么意思?我的页面源代码来自mysql到php变量。和页面源代码不一样。我不明白你在问什么。客户端加载的源在哪里?它必须被归还到某个地方。