Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

javascript - 获取页面网址,从网址中删除字符串,使用新网址嵌入src(Get page url, remove a string from URL, use new url for embed src)

I am using Google Drive PDF viewer to embed PDF files in HTML pages.(我正在使用Google云端硬盘PDF查看器将PDF文件嵌入HTML页面。)

I am doing multiple operations to modify the PDF URL to embed accordingly to certain conditions and store it into a variable.(我正在执行多项操作来修改PDF URL,以便根据特定条件进行嵌入并将其存储到变量中。) But finally, I cannot input the final URL in the embed src field.(但是最后,我无法在embed src字段中输入最终URL。) This is the entire script:(这是整个脚本:) <embed id="pdfDrive" src="temporary" width="100%" height="100%"> <script> var pdfURL = window.location.href; pdfURL.replace('/abbac.html?file=', '/'); var driveURL1 = 'https://drive.google.com/viewerng/' finalURL = driveURL1 + 'viewer?embedded=true&url=' + pdfURL; finalURL.replace('/abbac.html?file=', '/'); alert(finalURL.replace('/viewer.html?file=', '/')); document.getElementById('pdfDrive').src = finalURL; </script> Alert returns the correct URL ( finalURL is absolute url https://drive.google.com/viewerng/viewer?embedded=true&url=https://www.andreadd.it/appunti/polimi/ingegneria/corsi/en_mec_aes/comuni/anno1/analisi%20I/appunti/Appunti_riassuntivi.pdf ) but finalURL variable is not correctly given to src .(警报返回正确的URLfinalURL是绝对URL https://drive.google.com/viewerng/viewer?embedded=true&url=https://www.andreadd.it/appunti/polimi/ingegneria/corsi/en_mec_aes/comuni/ anno1 / analisi%20I / appunti / Appunti_riassuntivi.pdf ),但未将finalURL变量正确地赋予src 。) Embedded windows test is: 404 not found: URL requested https://www.andreadd.it:443/appunti/polimi/ingegneria/corsi/en_mec_aes/comuni/anno1/analisi%20I/temporary(嵌入式Windows测试是:找不到404:请求的URL https://www.andreadd.it:443/appunti/polimi/ingegneria/corsi/en_mec_aes/comuni/anno1/analisi%20I/temporary) src="temporary" is not updated with finalURL(src =“ temporary”未使用finalURL更新) Thank you(谢谢)   ask by Andrea De Donatis translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try using setAttribute on the fetched element.(您可以尝试在提取的元素上使用setAttribute 。)

For example - In your case, it would be like(例如-就您而言,这就像) const pdfDrive = document.getElementById('pdfDrive') pdfDrive.setAttribute('src', finalURL)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...