使用jQuery修改iframe的src:移除指定后缀并添加rel=0(无法直接编辑HTML)
修改iframe src属性的解决方案(无法直接编辑HTML时)
Got it, since you can't edit the HTML code directly, we can use JavaScript to dynamically tweak that iframe's src attribute exactly as you need after the page loads. Here's a straightforward approach:
Step-by-Step Breakdown
- Target the iframe using its unique
id(VideoContentin your case) - Extract the portion of the
srcURL before-C87LOjwkRw? - Append
rel=0to this base segment to form the desired final URL - Assign the modified URL back to the iframe's
srcproperty
Working Code Snippet
// Wait for the page to fully load so the iframe exists in the DOM document.addEventListener('DOMContentLoaded', function() { // Grab the target iframe element const videoIframe = document.getElementById('VideoContent'); if (videoIframe) { // Get the current src value let originalSrc = videoIframe.src; // Locate the specific string we need to cut after const targetMarker = '-C87LOjwkRw?'; const cutOffPoint = originalSrc.indexOf(targetMarker); if (cutOffPoint !== -1) { // Build the new src: keep everything up to the marker, then add rel=0 const newSrc = originalSrc.slice(0, cutOffPoint + targetMarker.length) + 'rel=0'; // Update the iframe's src attribute videoIframe.src = newSrc; } } });
How to Implement This
You can drop this code inside a <script> tag at the bottom of your HTML page, or run it directly in your browser's developer console for a quick one-time fix. The DOMContentLoaded event ensures the code only runs after all page elements have loaded, so we won't try to access the iframe before it exists in the DOM.
内容的提问来源于stack exchange,提问作者Jenny
相关产品推荐
相关产品推荐

